#ifndef BOARD_ESP32S3_LCKFB_SZPI_H
#define BOARD_ESP32S3_LCKFB_SZPI_H

#include <string.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/portmacro.h"
#include "esp_system.h"
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/i2c_master.h"
#include "driver/i2s_std.h"
#include "driver/spi_master.h"
#include "driver/ledc.h"
#include "nvs_flash.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_lcd_types.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "input_dev.h"
#include "extio_dev.h"
#include "msg_manager.h"
#include "task_manager.h"
#include "input_manager.h"
#include "audio_manager.h"
#include "lvgl_manager.h"
#include "fs_manager.h"
#include "ui_manager.h"
#include "hotplug_manager.h"
#include "media_service.h"
#include "sys_clock.h"
#include "device.h"
#include "nvs_config.h"
#include "task_define.h"

#ifdef __cplusplus
extern "C" {
#endif

/***** GPIO_DEFINE ***/
#define I2C0_SDA_IO         (GPIO_NUM_1)
#define I2C0_SCL_IO         (GPIO_NUM_2)

#define I2S_WS_IO           (GPIO_NUM_13)
#define I2S_BCK_IO          (GPIO_NUM_14)
#define I2S_MCK_IO          (GPIO_NUM_38)
#define I2S_DO_IO           (GPIO_NUM_45)
#define I2S_DI_IO           (GPIO_NUM_12)
#define I2S_PWR_IO          (GPIO_NUM_NC)

#define BSP_LCD_SPI_MOSI    (GPIO_NUM_40)
#define BSP_LCD_SPI_CLK     (GPIO_NUM_41)
#define BSP_LCD_SPI_CS      (GPIO_NUM_NC)
#define BSP_LCD_DC          (GPIO_NUM_39)
#define BSP_LCD_RST         (GPIO_NUM_NC)
#define BSP_LCD_BACKLIGHT   (GPIO_NUM_42)

#define BSP_SD_CLK          (GPIO_NUM_47)
#define BSP_SD_CMD          (GPIO_NUM_48)
#define BSP_SD_D0           (GPIO_NUM_21)

#define LCD_CS_IO           BIT(0)
#define PA_EN_IO            BIT(1)
#define DVP_PWDN_IO         BIT(2)

#define EXTERN_IO_MAP       LCD_CS_IO | PA_EN_IO | DVP_PWDN_IO
/*** End of GPIO_DEFINE ***/

/***** AUDIO_CONFIG ***/
#define BSP_I2S_NUM             (I2S_NUM_1)
#define EXAMPLE_RECV_BUF_SIZE   (2400)
#define EXAMPLE_SAMPLE_RATE     (16000)
#define EXAMPLE_MCLK_MULTIPLE   (384) // If not using 24-bit data width, 256 should be enough
#define EXAMPLE_MCLK_FREQ_HZ    (EXAMPLE_SAMPLE_RATE * EXAMPLE_MCLK_MULTIPLE)

#define CODEC_DEFAULT_SAMPLE_RATE          (48000)
#define CODEC_DEFAULT_BIT_WIDTH            (16)
#define CODEC_DEFAULT_ADC_VOLUME           (30.0)
#define CODEC_DEFAULT_CHANNEL              (2)
#define CODEC_DEFAULT_VOLUME               (70)
/*** End of AUDIO_CONFIG ***/

/***** KEY_CONFIG ***/
#define BOARD_ADCKEY_KEY_MAPPINGS \
    {0x30, 0x00}, \

#define BOARD_GPIO_KEY_MAPPINGS \
    {KEY_POWER, GPIO_NUM_0, 0}, \

#define CONFIG_INPUT_MUTIPLE_CLICK 0
#define HOLDABLE_KEY  {KEY_TBD}
#define MUTIPLE_CLIK_KEY  {KEY_POWER, KEY_TBD}
/*** End of KEY_CONFIG ***/

/***** LCD_CONFIG ***/
#define BSP_I2C_NUM                (0)            // I2C外设
#define BSP_LCD_PIXEL_CLOCK_HZ     (80 * 1000 * 1000)
#define BSP_LCD_SPI_NUM            (SPI3_HOST)
#define LCD_CMD_BITS               (8)
#define LCD_PARAM_BITS             (8)
#define BSP_LCD_BITS_PER_PIXEL     (16)
#define LCD_LEDC_CH                (LEDC_CHANNEL_0)
#define BSP_LCD_DRAM_BUF_HEIGHT    (40)

#define BSP_LCD_W_RES              (320)
#define BSP_LCD_H_RES              (240)
/*** End of LCD_CONFIG ***/


void board_init();
void manager_init();
void sys_set_pa_level(uint8_t level);
void sys_set_lcd_cs_level(uint8_t level);
void sys_set_dvp_pwdn_level(uint8_t level);

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /* BOARD_ESP32S3_LCKFB_SZPI_H */